package cn.achao.csr.system.service.impl;

import cn.achao.csr.system.service.TestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.concurrent.Future;

/**
 * @Author: achao
 **/
@Slf4j
@Service("TestServiceImpl")
public class TestServiceImpl implements TestService {

    @Override
    public String sleep(Long time) {
        try {
            Thread.sleep(time);
            log.info("非异步 睡了{}...", time);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return "";
    }

    @Override
    public String playGame() {
        log.info("非异步 playGame");
        return "打游戏";
    }

    @Override
    public Future<String> goHome(Long time) {
        try {
            Thread.sleep(time);
            log.info("非异步 花了{}回到了家", time);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return new AsyncResult<>("回到家");
    }
}
